# Historical scaffold note — v393

This file is an old integrated backend scaffold note. It is preserved for history only and should not guide current Dispatch Spot build cycles. Use the controlled `Project Documentation/` folder and current build rules instead.

---

Dispatch Spot integrated backend scaffold

This package consolidates the prior backend scaffold batches into a single starter codebase.

Included layers:
1. Foundation
   - Prisma client singleton
   - env loader
   - response helpers
   - auth service and guards
   - organization/user guards
   - trucks and brokers modules
   - auth/trucks/brokers API routes

2. Core modules
   - drivers
   - loads
   - load status history
   - truck financial settings
   - drivers/loads/status/financial-settings API routes

3. Financial and reporting
   - payments
   - expenses
   - accessorials
   - weekly summaries
   - truck metrics
   - related API routes

4. AI and platform
   - feature flags
   - domain events
   - job queue helper
   - AI orchestrator
   - document parsing scaffold
   - insight generation scaffold
   - related AI API routes

Important notes:
- This is a scaffold, not a complete production backend.
- Validation is intentionally lightweight and should be replaced with Zod schemas.
- Session handling is simplified and should be connected to your actual auth/session strategy.
- AI parsing and insights currently use deterministic placeholder logic and do not call an external model yet.
- Weekly summaries and KPI snapshots are scaffolded with direct deterministic calculations and should be wired into your real job/rebuild flow.

Recommended next implementation steps:
1. Add Zod validation schemas for every route payload.
2. Add route-by-route role and tenant guards comprehensively.
3. Add update/rebuild jobs after payments, expenses, accessorials, and load changes.
4. Add document upload/storage implementation.
5. Replace placeholder AI extraction with real OCR/LLM pipeline.
6. Add load update/detail routes and document/note CRUD routes.
7. Add integration tests around calculations and status transitions.

Suggested dependency snippet remains in:
- package.backend.foundation.snippet.json

Suggested TypeScript config remains in:
- tsconfig.backend.foundation.json
